//
//  RightView.m
//  FiltrationSystem
//
//  Created by 123456 on 2017/2/10.
//  Copyright © 2017年 YTYangK. All rights reserved.
//

#import "RightView.h"

@implementation RightView
{
    NSDictionary *parameterDic;

}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.RightTableView.backgroundColor = RGB(33, 38, 44, 1);
    self.RightTableView.tableFooterView=   [[UIView alloc]init];//隐藏多余的分割线
    [self.RightTableView registerNib:[UINib nibWithNibName:@"RightTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
}





#pragma mark -  TableView DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {

    return 1;
    
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger row = self.RightModelAry.count;
return row;
    
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    
    RightTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    [cell vlueWithList:self.RightModelAry[indexPath.row]];
    cell.backgroundColor = RGB(33, 38, 44, 1);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//取消点击效果
    
    
    return cell;
}

- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
    return [NSString stringWithFormat:@"总数：%ld" ,self.RightModelAry.count];
}

-(CGFloat)tableView:(UITableView*)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 35.0;
}

- (void)tableView:(UITableView*)tableView willDisplayHeaderView:(UIView*)view forSection:(NSInteger)section
{
    UITableViewHeaderFooterView* header = (UITableViewHeaderFooterView*)view;
    [header.textLabel setTextColor:RGB(200, 200, 200, 0.9)];
    [header.textLabel setBackgroundColor:RGB(33, 38, 44, 1)];
    UIFont* bodyFont = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
    [header.textLabel setFont:bodyFont];
    header.contentView.backgroundColor = RGB(33, 38, 44, 1);
}


/**
 * 请求大头针设备列表
 */
-(void)requestURLwithViewForMapRightList:(NSString *)latitude An:(NSString *)longitude{

    parameterDic = @{@"token":[NSUD objectForKey:@"token"],@"longitude":longitude,@"latitude":latitude};
    
    
    NSLog(@"%@",parameterDic);
    
    
    [RightViewModel requestWithUrlForMap:self andParam:parameterDic success:^(NSMutableArray *model) {
        
        NSMutableArray *RightListAry = [RightModel mj_objectArrayWithKeyValuesArray:model];
        
        [self.RightModelAry removeAllObjects];
        
        for (NSDictionary *dic in RightListAry) {
            [self.RightModelAry addObject:dic];
            
        }
        
        [self.RightTableView reloadData];
        
    } failure:^(NSString *error) {
        UIWindow * window = [UIApplication sharedApplication].keyWindow;

        [MBProgressHUD yty_showErrorWithTitle:nil detailsText:error toView:window];
    }];
}



-(NSMutableArray *)RightModelAry
{
    if (!_RightModelAry) {
        _RightModelAry = [[NSMutableArray alloc]init];
    }
    return _RightModelAry;
}


@end
